/*
 * @Author: 黑白灰01 3193273703@qq.com
 * @Date: 2025-09-01 14:31:38
 * @LastEditors: 黑白灰01 3193273703@qq.com
 * @LastEditTime: 2025-09-01 14:40:36
 * @FilePath: /hei-oa/src/common/response/base-response.dto.ts
 * @Description: 状态码返回封装类
 */
// src/common/response/base-response.dto.ts
import { ApiProperty } from '@nestjs/swagger';
import { RESPONSE_CODE, RESPONSE_MSG } from 'src/common/enums/code';

export class BaseResponse<T> {
  @ApiProperty({ 
    description: '状态码',
    enum: RESPONSE_CODE,
    example: RESPONSE_CODE.SUCCESS
  })
  code: RESPONSE_CODE;

  @ApiProperty({ 
    description: '提示信息',
    enum: RESPONSE_MSG,
    example: RESPONSE_MSG.SUCCESS
  })
  msg: string;

  @ApiProperty({ 
    description: '实际返回数据' 
  })
  data?: T;

  constructor(
    code: RESPONSE_CODE,
    msg: string,
    data?: T,
    path?: string
  ) {
    this.code = code;
    this.msg = msg;
    this.data = data;
  }

  static success<T>(data: T, path?: string): BaseResponse<T> {
    return new BaseResponse<T>(
      RESPONSE_CODE.SUCCESS, 
      RESPONSE_MSG.SUCCESS, 
      data, 
    );
  }

  static error(
    code: RESPONSE_CODE,
    message: string,
    path?: string
  ): BaseResponse<any> {
    return new BaseResponse<any>(code, message, undefined, path);
  }
}